﻿using System;
using System.IO;
using LogException.Dominio.Repositorios;

namespace LogException.InfraEstrutura
{
   public class RepositorioArquivoTexto :IArquivoTexto
    {
     
        public void AdicionaLog(string innerException, string message, string source, string stacktrace, string caminhoDoArquivo)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(caminhoDoArquivo, true))
                {
                    writer.WriteLine("------------------------------------------------------------------------------------");
                    writer.WriteLine(DateTime.Now.ToString("dd/MM/yyyy") + "-" + source);
                    writer.WriteLine("------------------------------------------------------------------------------------");
                    writer.WriteLine("Message:         " + message);
                    writer.WriteLine("Stack Trace:     " + stacktrace);
                    writer.WriteLine("Inner Exception: " + innerException);
                    writer.WriteLine("------------------------------------------------------------------------------------");
                }
            }
            catch { }
        }

        public void AdicionaLog(string message, string source, string caminhoDoArquivo)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(caminhoDoArquivo, true))
                {
                    writer.WriteLine("------------------------------------------------------------------------------------");
                    writer.WriteLine(DateTime.Now.ToString("dd/MM/yyyy") + "-" + source);
                    writer.WriteLine("------------------------------------------------------------------------------------");
                    writer.WriteLine("Message:         " + message);
                    writer.WriteLine("------------------------------------------------------------------------------------");
                }
            }
            catch { }
        }

        public void CriaArquivoDeLog(string caminhoDoArquivo)
        {
            if (!File.Exists(caminhoDoArquivo))
                File.Create(caminhoDoArquivo).Close();
        }
    }
}
